package com.neusoft.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.neusoft.db.DBDriver;
import com.neusoft.db.DBDriverFactoory;

public class TestDriver {

	public static void main(String[] args) {

		test03();

	}

	/**
	 * myUtil方法利用list
	 */
	private static void test03() {
		int deptno = 30;
		String strSql = "select  * from emp where deptno=" + deptno;
		List<Map<String, Object>> lsts = DBDriverFactoory.getDBDriverInstance().doQueryListMap(strSql);
		for (Map<String, Object> map : lsts) {
			Set<String> keys = map.keySet();
			for (String key : keys) {
				System.out.print("    " + key + "-" + map.get(key));
			}
			System.out.println();
		}
	}

	private static void test1() {
		try {
			String dBDriver = "oracle.jdbc.driver.OracleDriver";
			DBDriver db = new DBDriver();
			Connection conn = db.getConn();
			Statement st = conn.createStatement();

			String strSql = "select *from emp";
			ResultSet rs = db.doQuery(strSql);
			while (rs.next()) {
				System.out.println("empno-" + rs.getInt(1) + ";empname-" + rs.getString("ename"));
			}
			rs.close();
			st.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	private static void test() {
		// TODO Auto-generated method stub
		try {
			String dBDriver = "oracle.jdbc.driver.OracleDriver";
			String url = "jdbc:oracle:thin:@localhost:1521:orcl";
			String userName = "scott";
			String password = "tiger";
			Class.forName(dBDriver).newInstance();
			Connection conn = DriverManager.getConnection(url, userName, password);
			Statement st = conn.createStatement();
			String strSql = "select *from emp";
			ResultSet rs = st.executeQuery(strSql);
			while (rs.next()) {
				System.out.println("empno-" + rs.getInt(1) + ";empname-" + rs.getString("ename"));
			}
			rs.close();
			st.close();
			conn.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
